import actionType from './actionType'

export function setDrawWin(type, payload) {
	if (type === 'func') {
		return {
			type: actionType.SET_FUNC_WINDOW,
			payload,
		}
	} else {
		return {
			type: actionType.SET_GRAPH_WINDOW,
			payload,
		}
	}
}
export function closeWin() {
	return {
		type: actionType.CLOSE_WINDOW,
	}
}
export function updateBasicInfo(basicInfo) {
	return {
		type: actionType.UPDATE_BASIC_INFO,
		basicInfo,
	}
}

export function formatNewObjToDraw(payload) {
	let { detailedType, params, type, fae } = payload
	const action = {}
	if (type === 'func') {
		if (fae) {
			action.type = actionType.ADD_FUNC_BY_FAE
			action.payload = {
				fae,
				type: detailedType,
			}
		} else {
			action.type = actionType.ADD_FUNC_BY_PARAMS
			action.payload = {
				params,
				type: detailedType,
			}
		}
	} else {
		action.type = actionType.ADD_GRAPH
		action.payload = {
			params,
			type: detailedType,
		}
	}
	return action
}
export function editObj(payload) {
	let { detailedType, name, params, color, width, type, fae, edit } = payload
	const action = {}
	if (type === 'func') {
		if (!params.length) {
			action.type = actionType.EDIT_FUNC_BY_FAE
			action.payload = {
				edit,
				name,
				fae,
				style: { color, width },
			}
		} else {
			action.type = actionType.EDIT_FUNC_BY_PARAMS
			action.payload = {
				edit,
				name,
				params,
				type: detailedType,
				style: { color, width },
			}
		}
	} else {
		action.type = actionType.EDIT_GRAPH
		action.payload = {
			edit,
			name,
			params,
			type: detailedType,
			style: { color, width },
		}
	}
	return action
}
export function deleteOne(payload) {
	return {
		type: actionType.DELETE_ONE,
		payload,
	}
}
export function toggleHiddenState(payload) {
	return {
		type: actionType.TOGGLE_HIDDEN_STATE,
		payload,
	}
}
export function resetToRedraw() {
	return {
		type: actionType.RESET_TO_REDRAW,
	}
}
